package org.sn.jdish.interview.dmall.orderthread;

public class OrderThread extends Thread {

	private LockObject lockObject;
	private int printNum = 0;

	public OrderThread(LockObject lockObject, int printNum) {
		this.lockObject = lockObject;
		this.printNum = printNum;
	}

	@Override
	public void run() {
		synchronized (lockObject) {
			while (lockObject.orderNum < lockObject.maxValue) {
				if (lockObject.orderNum == printNum) {
					System.out.print(printNum);
					lockObject.orderNum++;
					if (lockObject.orderNum == 10) {
						System.out.print("end");
					}
					lockObject.notifyAll();
				} else {
					try {
						lockObject.wait();
					} catch (InterruptedException e) {
						e.printStackTrace();
					}
				}
			}
		}
	}
}
